package com.study.controller;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloController implements Controller {

    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        //ModelAndView 模型和视图
        ModelAndView mv = new ModelAndView();

        //封装对象，放在ModelAndView中。Model
        mv.addObject("msg","HelloSpringMVC!");
        //封装要跳转的视图，放在ModelAndView中
        mv.setViewName("hello");   //: /WEB-INF/jsp/hello.jsp return mv;
        return mv;

        /*
        可能遇到的问题 : 访问404
        1. 查看控制台 , 看是不是少jar包
        2. 如果jar包存在,显示无法输出,在idea中添加lib依赖,
        3. 打开项目结构找到该项目WEB-INF下是否有lib,没有就新建,点击加号在新建的lib下添加所有库文件,然后重启输入 localhost:8080/hello
         */
    }
}
